package com.wx.main;
import com.wx.pojo.AccessToken;
import com.wx.pojo.Button;
import com.wx.pojo.CommonButton;
import com.wx.pojo.ComplexButton;
import com.wx.pojo.Menu;
import com.wx.util.WeixinUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 菜单管理器类
 * 
 * @author liaoxj
 * @date 2014-07-07
 */
public class MenuManager {
	private static Logger log = LoggerFactory.getLogger(MenuManager.class);

	public static void main(String[] args) {
		// 第三方用户唯一凭证
		String appId = "000000000000000000";
		// 第三方用户唯一凭证密钥
		String appSecret = "00000000000000000000000000000000";

		// 调用接口获取access_token
		AccessToken at = WeixinUtil.getAccessToken(appId, appSecret);

		if (null != at) {
			// 调用接口创建菜单
			int result = WeixinUtil.createMenu(getMenu(), at.getToken());
			// 判断菜单创建结果
			if (0 == result)
				log.info("菜单创建成功！");
			else
				log.info("菜单创建失败，错误码：" + result);
		}
	}

	/**
	 * 组装菜单数据
	 * 
	 * @return
	 */
	public static Menu getMenu() {
		CommonButton btn11 = new CommonButton();
		btn11.setName("2014年7月");
		btn11.setType("click");
		btn11.setKey("V1001_2014_05");

		CommonButton btn12 = new CommonButton();
		btn12.setName("2014年6月");
		btn12.setType("click");
		btn12.setKey("V1001_2014_04");

		CommonButton btn13 = new CommonButton();
		btn13.setName("2014年5月");
		btn13.setType("click");
		btn13.setKey("V1001_2014_03");

		CommonButton btn14 = new CommonButton();
		btn14.setName("2014年4月");
		btn14.setType("click");
		btn14.setKey("V1001_2014_02");

		CommonButton btn15 = new CommonButton();
		btn15.setName("2014年3月");
		btn15.setType("click");
		btn15.setKey("V1001_2014_01");

		CommonButton btn21 = new CommonButton();
		btn21.setName("西曼时尚教育");
		btn21.setType("click");
		btn21.setKey("V2001_FASHION_EDU");
		
		CommonButton btn22 = new CommonButton();
		btn22.setName("形象会所");
		btn22.setType("click");
		btn22.setKey("V2001_CLUB_IMAGE");

		CommonButton btn23 = new CommonButton();
		btn23.setName("城市色彩规划");
		btn23.setType("click");
		btn23.setKey("V2001_CITY_PLAN");

		CommonButton btn24 = new CommonButton();
		btn24.setName("企业培训");
		btn24.setType("click");
		btn24.setKey("V2001_ENTERPRISE_TRAIN");
		
		CommonButton btn31 = new CommonButton();
		btn31.setName("品牌故事");
		btn31.setType("click");
		btn31.setKey("V3001_BRAND_STORY");

		CommonButton btn32 = new CommonButton();
		btn32.setName("品牌大事件");
		btn32.setType("click");
		btn32.setKey("V3001_BRAND_EVENTS");

		CommonButton btn33 = new CommonButton();
		btn33.setName("关于我们");
		btn33.setType("click");
		btn33.setKey("V3001_ABOUT_US");

		ComplexButton mainBtn1 = new ComplexButton();
		mainBtn1.setName("西曼资讯");
		mainBtn1.setSub_button(new CommonButton[] { btn11, btn12, btn13, btn14,btn15 });

		ComplexButton mainBtn2 = new ComplexButton();
		mainBtn2.setName("公司业务");
		mainBtn2.setSub_button(new CommonButton[] { btn21, btn22, btn23, btn24 });

		ComplexButton mainBtn3 = new ComplexButton();
		mainBtn3.setName("关于西曼");
		mainBtn3.setSub_button(new CommonButton[] { btn31, btn32, btn33 });

		/**
		 * 这是公众号xiaoqrobot目前的菜单结构，每个一级菜单都有二级菜单项<br>
		 * 
		 * 在某个一级菜单下没有二级菜单的情况，menu该如何定义呢？<br>
		 * 比如，第三个一级菜单项不是“更多体验”，而直接是“幽默笑话”，那么menu应该这样定义：<br>
		 * menu.setButton(new Button[] { mainBtn1, mainBtn2, btn33 });
		 */
		Menu menu = new Menu();
		menu.setButton(new Button[] { mainBtn1, mainBtn2, mainBtn3 });

		return menu;
	}
}